<template>
  <view class="onboarding-container">
    <!-- 轮播图引导页 -->
    <swiper 
      class="swiper" 
      :indicator-dots="true" 
      :autoplay="false"
      :current="currentIndex"
      @change="onSwiperChange"
    >
      <swiper-item v-for="(item, index) in slides" :key="index" class="slide-item">
        <view class="slide-content">
          <image :src="item.image" class="slide-image" mode="aspectFit" />
          <view class="slide-title">{{ item.title }}</view>
          <view class="slide-desc">{{ item.description }}</view>
        </view>
      </swiper-item>
    </swiper>

    <!-- 底部导航 -->
    <view class="bottom-nav">
      <view class="indicators">
        <view 
          v-for="(item, index) in slides" 
          :key="index"
          class="indicator"
          :class="{ active: currentIndex === index }"
        ></view>
      </view>
      
      <view class="nav-buttons">
        <button 
          v-if="currentIndex < slides.length - 1" 
          class="skip-btn" 
          @click="skipOnboarding"
        >
          跳过
        </button>
        <button 
          class="action-btn"
          :class="{ primary: currentIndex === slides.length - 1 }"
          @click="handleNext"
        >
          {{ currentIndex === slides.length - 1 ? '立即体验' : '下一步' }}
        </button>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
      slides: [
        {
          image: '',
          title: '欢迎使用医疗就医小程序',
          description: '便捷的医疗服务，一站式解决您的就医需求'
        },
        {
          image: '', 
          title: '智能导航定位',
          description: '精准的院内导航，快速找到目标科室和设施'
        },
        {
          image: '',
          title: '在线挂号预约',
          description: '随时随地预约挂号，避免排队等待'
        },
        {
          image: '',
          title: '药品查询购买',
          description: '查询药品信息，在线购买配送到家'
        }
      ]
    }
  },
  methods: {
    onSwiperChange(event) {
      this.currentIndex = event.detail.current
    },
    handleNext() {
      if (this.currentIndex < this.slides.length - 1) {
        this.currentIndex++
      } else {
        this.completeOnboarding()
      }
    },
    skipOnboarding() {
      this.completeOnboarding()
    },
    completeOnboarding() {
      // 标记已查看引导页
      uni.setStorageSync('hasViewedOnboarding', true)
      
      // 跳转到首页
      uni.reLaunch({
        url: '/pages/home/index'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.onboarding-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.swiper {
  flex: 1;
  width: 100%;
}

.slide-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80rpx 60rpx;
}

.slide-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.slide-image {
  width: 400rpx;
  height: 400rpx;
  margin-bottom: 60rpx;
  border-radius: 20rpx;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10rpx);
}

.slide-title {
  font-size: 48rpx;
  font-weight: bold;
  color: #fff;
  margin-bottom: 32rpx;
  line-height: 1.4;
}

.slide-desc {
  font-size: 32rpx;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.6;
  max-width: 500rpx;
}

.bottom-nav {
  padding: 60rpx 60rpx 100rpx;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(20rpx);
}

.indicators {
  display: flex;
  justify-content: center;
  margin-bottom: 50rpx;
  gap: 20rpx;
}

.indicator {
  width: 20rpx;
  height: 20rpx;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
  
  &.active {
    background: #fff;
    transform: scale(1.2);
  }
}

.nav-buttons {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 32rpx;
}

.skip-btn {
  background: transparent;
  border: 2rpx solid rgba(255, 255, 255, 0.5);
  color: rgba(255, 255, 255, 0.9);
  padding: 24rpx 48rpx;
  border-radius: 50rpx;
  font-size: 28rpx;
}

.action-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.2);
  border: 2rpx solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 28rpx 48rpx;
  border-radius: 50rpx;
  font-size: 32rpx;
  font-weight: 500;
  transition: all 0.3s ease;
  
  &.primary {
    background: #fff;
    color: #667eea;
    border-color: #fff;
    font-weight: 600;
  }
}

.skip-btn:active,
.action-btn:active {
  transform: scale(0.98);
  opacity: 0.8;
}

/* 动画效果 */
.slide-content {
  animation: slideInUp 0.6s ease-out;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(60rpx);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>